package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private ISearchService iSearchService;

    @GetMapping("/suggestion")
    public List<String> autoComplement(@RequestParam String key) throws IOException {
        List<String> list = iSearchService.autoComplement(key);
        return list;
    }

    @PostMapping("/filters")
    public Map<String,List<String>> filterIndex(@RequestBody RequestParams params){
        Map<String,List<String>> map = iSearchService.filterIndex(params);
        return map;
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> listQuery(@RequestBody RequestParams params){
        PageDTO<ItemDoc> pageDTO = iSearchService.listQuery(params);
        return pageDTO;
    }
}
